function fs_init()
{
	fs_decale_liste = 0
	fs_decale_liste_old = 0
	fs_last_directory = -1
	fs_unit_dur = "C"
	fs_repertoire = fs_path_default.substring(3 , fs_path_default.length)  
	fs_nb_files = 0
	fs_numero = 0
	fs_old_numero = 0
	fs_get_parent = false
	fs_possible = "jpg;jpeg;bmp;svg;gif;png"
	list_files = new Array()
	svgdoc.getElementById("fs_header").firstChild.data = fs_invite
	svgdoc.getElementById("fs_ok").firstChild.data = popup_message[6]
	svgdoc.getElementById("fs_cancel").firstChild.data = popup_message[7]
	svgdoc.getElementById("fs_previous").setAttribute("visibility","hidden")
	svgdoc.getElementById("fs_next").setAttribute("visibility","hidden")
	if (fs_path_default.indexOf("patterns") >= 0)
	{
		svgdoc.getElementById("fs_scroll_picture").setAttribute("y" , 95)
		svgdoc.getElementById("fs_scroll_picture").setAttribute("height" , 120)
	}
	getDataFile("php/file_system.php?unit=" + fs_unit_dur + "&path=" + fs_path_default,fs_callback1)
}

function fs_callback1(data)
{
	fs_last_directory = -1
	fs_nb_files = 0
	if (data.content.length == 1 )
	{
		fs_nb_files = 0
		fs_repertoire = fs_unit_dur + ":"
	}
	else
	{
		if (data.content.indexOf("#") != 0)
		{
			list_files = data.content.substring(0,data.content.lastIndexOf("#") - 1).split(";")
			fs_last_directory = list_files.length - 1
		}
	
		if (data.content.indexOf("#") < data.content.length)
		{
			var list_files2 = data.content.substring(data.content.indexOf("#") + 1,data.content.length - 1).split(";")
			var k = fs_last_directory
			for ( i = 0 ; i < list_files2.length ; i ++)
				if (fs_filtre.indexOf(list_files2[i].substring(list_files2[i].lastIndexOf(".") + 1,list_files2[i].length)) >= 0)
				{
					k += 1
					list_files[k] = list_files2[i]
				}

			fs_nb_files = k + 1
		}
		else
			fs_nb_files = fs_last_directory + 1
	}
	if (fs_get_parent)
	{
		fs_decale_liste = fs_decale_liste_old
		if (fs_nb_files < 13 * fs_decale_liste)
			fs_decale_liste = 0
		fs_decale_liste_old = 0
		fs_get_parent = false
		if (fs_decale_liste == 0)
			svgdoc.getElementById("fs_previous").setAttribute("visibility","hidden")
		else
			svgdoc.getElementById("fs_previous").setAttribute("visibility","visible")
	}
	else
	{
		fs_decale_liste = 0
		svgdoc.getElementById("fs_previous").setAttribute("visibility","hidden")
	}
	svgdoc.getElementById("fs_dir_current").firstChild.data = fs_repertoire
	fs_write_files()
}

function fs_write_units()
{
	for (var i = 0 ; i < list_units.length ; i ++)
	{
		var node = svgdoc.createElementNS("http://www.w3.org/2000/svg","use")
		node.setAttribute("x" , "445")
		node.setAttribute("y" , (37 + 25 * i).toString())
		node.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href" , "#unite")
		node.setAttribute("cursor" , "pointer")
		svgdoc.getElementById("fs_liste_units").appendChild(node)
		var node = svgdoc.createElementNS("http://www.w3.org/2000/svg","text")
		node.setAttribute("x" , "445")
		node.setAttribute("y" , (48 + 25 * i).toString())
		node.setAttribute("font-size" , "10")
		node.setAttribute("pointer-events" , "none")
		node.setAttribute("text-anchor" , "middle")
		var texte=svgdoc.createTextNode(list_units[i]);
		node.appendChild(texte);
		svgdoc.getElementById("fs_liste_units").appendChild(node)
	}
}

function fs_write_files()
{
	remove_window("fs_liste_files")
	fs_numero = 13 * fs_decale_liste
	for (var i = 13 * fs_decale_liste ; i < 13 * ( fs_decale_liste + 1 ) ; i ++)
		if ( i < fs_nb_files )
		{
			var node = svgdoc.createElementNS("http://www.w3.org/2000/svg","use")
			node.setAttributeNS(null , "x" , "242")
			node.setAttributeNS(null , "y" , (37 + 15 * (i % 13)).toString())
			if (i <= fs_last_directory)
				node.setAttributeNS("http://www.w3.org/1999/xlink" , "xlink:href" , "#directory")
			else
				node.setAttributeNS("http://www.w3.org/1999/xlink" , "xlink:href" , "#file")
			svgdoc.getElementById("fs_liste_files").appendChild(node)
			var node = svgdoc.createElementNS("http://www.w3.org/2000/svg","text")
			node.setAttributeNS(null ,"x" , "255")
			node.setAttributeNS(null ,"y" , (45 + 15 * (i % 13)).toString())
			node.setAttributeNS(null,"font-size" , "8")
			var texte=svgdoc.createTextNode( list_files[i].substring(list_files[i].lastIndexOf("\\") + 1,list_files[i].length))
			node.appendChild(texte);
			svgdoc.getElementById("fs_liste_files").appendChild(node)
		}
	if (13 * fs_decale_liste < fs_nb_files)
	{
		svgdoc.getElementById("fs_file_chosen").setAttribute("visibility","visible")
		var file_current = list_files[13 * fs_decale_liste]
	}
	else
	{
		svgdoc.getElementById("fs_file_chosen").setAttribute("visibility","hidden")
		var file_current = " "
	}
	svgdoc.getElementById("fs_file_chosen").setAttribute("y","35")
	svgdoc.getElementById("fs_file_current").firstChild.data = file_current
	if (13 * fs_decale_liste > fs_last_directory)
		if (fs_possible.indexOf(list_files[13 * fs_decale_liste].substring(list_files[13 * fs_decale_liste].indexOf(".") + 1,list_files[13 * fs_decale_liste].length)) >= 0)
			svgdoc.getElementById("fs_scroll_picture").setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",fs_repertoire + "/" + list_files[13 * fs_decale_liste])
		else
			svgdoc.getElementById("fs_scroll_picture").setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","png/none.svg")
	if (13 * ( fs_decale_liste + 1 ) < fs_nb_files)
		svgdoc.getElementById("fs_next").setAttribute("visibility","visible")
	else
		svgdoc.getElementById("fs_next").setAttribute("visibility","hidden")
}

function fs_show_directory(evt)
{
	if (ASV == 6)
	{
		var matrix = svgdoc.getElementById("fs_liste_units").getScreenCTM().inverse()
		ym = evt.clientX * matrix.b + evt.clientY * matrix.d + matrix.f - 35 
	}
	else
	{
		var matrix = svgdoc.getElementById(prefixe_tool).getCTM().inverse()
		var xm1 = coordo_x(evt.clientX) 
		var ym1 = coordo_y(evt.clientY)
		ym = xm1 * matrix.b + ym1 * matrix.d + matrix.f - 50
	}
	fs_numero = Math.floor(ym / 15) + 13 * fs_decale_liste
	if (fs_numero <= fs_last_directory)
	{
		fs_path_default = fs_path_default + list_files[fs_numero] + "/"
		getDataFile("php/file_system.php?unit=" + fs_unit_dur + "&path=" + fs_path_default,fs_callback1)
	
	}
	else
	{
		if (fs_numero < fs_nb_files)
		{
			if (fs_possible.indexOf(list_files[fs_numero].substring(list_files[fs_numero].indexOf(".") + 1,list_files[fs_numero].length)) >= 0)
				svgdoc.getElementById("fs_scroll_picture").setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",fs_repertoire + "/" + list_files[fs_numero])
			else
				svgdoc.getElementById("fs_scroll_picture").setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","png/none.svg")
			svgdoc.getElementById("fs_file_current").firstChild.data = list_files[fs_numero]
			svgdoc.getElementById("fs_file_chosen").setAttribute("y",(35 + 15 * (fs_numero % 13)).toString())
			fs_old_numero = fs_numero
		}
		else
			fs_numero = fs_old_numero 
	}
}

function fs_change_page(step)
{
	fs_decale_liste =  fs_decale_liste + parseInt(step)
	fs_decale_liste_old = fs_decale_liste 
	if (fs_decale_liste == 0)
		svgdoc.getElementById("fs_previous").setAttribute("visibility","hidden")
	else
		svgdoc.getElementById("fs_previous").setAttribute("visibility","visible")
	fs_write_files()
}

function fs_change_unit(evt)
{
	var matrix = svgdoc.getElementById("fs_liste_units").getScreenCTM().inverse()
	var ym = evt.clientX * matrix.b + evt.clientY * matrix.d + matrix.f - 37
	var numero = Math.floor(ym / 25)
	if (numero <= list_units.length)
	{
		fs_unit_dur = list_units[numero].substring(0,list_units[numero].indexOf(":"))
		getDataFile("php/file_system.php?unit=" + fs_unit_dur + "&path=",fs_callback1)
	}
}

function fs_parent()
{
	fs_get_parent = true
	fs_repertoire = fs_unit_dur + ":/" + fs_path_default 
	fs_path_default  = fs_path_default.substring(0 ,fs_path_default.length - 1)
	fs_path_default  = fs_path_default.substring(0 ,fs_path_default.lastIndexOf("/") + 1)
	getDataFile("php/file_system.php?unit=" + fs_unit_dur + "&path=" + fs_path_default,fs_callback1)

}


